<?php namespace App\Http\Controllers\user\uc\devicetech;

use App\Http\Requests;
use App\Http\Controllers\Controller;

use Illuminate\Http\Request;
use Input;
use Session;
use Validator;
use App\Models\DevicetechProviderIndustry;

class IndustryInfoController extends Controller {

	/**
	 * Display a listing of the resource.
	 *
	 * @return Response
	 */
	public function index()
	{
		$uid = $this->getUid();
		$model = DevicetechProviderIndustry::where('uid', $uid);
		if($model->count()){
			$data = $model->get()[0]->toArray();
		}else{
			$data = [];
		}
		return view('user.uc.devicetech.industryinfo', ['data' => $data])->withIsDeviceIndustry(true);
	}

	public function editIndustryInfo()
	{
		return view('user.uc.devicetech.edit_industryinfo')->withIsDeviceIndustry(true);
	}


	public function updateIndustryinfo()
	{
		$rule = array(
			// 'company_name'	=>	'required'
			);
		$msg = array();
		$validator = Validator::make(Input::all(), $rule, $msg);
		if($validator->passes()){
			$uid = $this->getUid();
			$model = DevicetechProviderIndustry::where('uid', $uid);
			if($model->count()){
				$data = Input::except('imgFile');

				$imgArr = Input::only("bank_credit_copy");
				$this->moveImages($imgArr, env("OTHERS_DIR"));

				$model->update($data);
				return $this->json([]);
			}else{
				$data = Input::except('imgFile');
				$data['uid'] = $uid;
				DevicetechProviderIndustry::create($data);
				return $this->json([]);
			}
		}else{
			return self::error(self::DATA_IS_WRONG);
		}
	}

	public function industryinfoList()
	{
		$uid = $this->getUid();
		$model = DevicetechProviderIndustry::where('uid', $uid);
		if($model->count()){
			$data = $model->get()[0];
			return $this->json($data);
		}else{
			return self::error(self::NO_DATA);
		}
	}

	// 后台用户列表

	/**
	 * Show the form for creating a new resource.
	 *
	 * @return Response
	 */
	public function create()
	{
		//
	}

	public function addSaver()
	{

	}

	/**
	 * Store a newly created resource in storage.
	 *
	 * @return Response
	 */
	public function store()
	{
		//
	}

	/**
	 * Display the specified resource.
	 *
	 * @param  int  $id
	 * @return Response
	 */
	public function show($id)
	{
		//
	}

	/**
	 * Show the form for editing the specified resource.
	 *
	 * @param  int  $id
	 * @return Response
	 */
	public function edit($id)
	{
		//
	}

	/**
	 * Update the specified resource in storage.
	 *
	 * @param  int  $id
	 * @return Response
	 */
	public function update($id)
	{
		//
	}

	/**
	 * Remove the specified resource from storage.
	 *
	 * @param  int  $id
	 * @return Response
	 */
	public function destroy($id)
	{
		//
	}
}
